package com.faithbj.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.faithbj.common.dao.impl.BaseDaoImpl;
import com.faithbj.common.model.compare.CompareRecord;
import com.faithbj.dao.CompareRecordDao;

@Repository("compareRecordDao")
public class CompareRecordDaoImpl extends BaseDaoImpl<CompareRecord, String>implements CompareRecordDao {

	@Override
	public List<CompareRecord> queryCompareRecordListByCondition(Map condition) {
		// TODO Auto-generated method stub
		Session session = this.getSession();
		Criteria criteria = session.createCriteria(CompareRecord.class);
		if(condition.get("regionId") != null) {
			criteria.add(Restrictions.eq("regionId", condition.get("regionId")));
		}
		if(condition.get("acceptStartTime") != null) {
			criteria.add(Restrictions.ge("acceptTime", condition.get("acceptStartTime")));
		}
		if(condition.get("acceptEndTime") != null) {
			criteria.add(Restrictions.le("acceptTime", condition.get("acceptEndTime")));
		}
		if(condition.get("type") != null) {
			criteria.add(Restrictions.eq("type", (Integer)condition.get("type")));
		}
		if(condition.get("startCreateTime") != null) {
			criteria.add(Restrictions.ge("createDate", condition.get("startCreateTime")));
		}
		if(condition.get("endCreateTime") != null) {
			criteria.add(Restrictions.le("createDate", condition.get("endCreateTime")));
		}
		if(condition.get("startUpdateTime") != null) {
			criteria.add(Restrictions.ge("modifyDate", condition.get("startUpdateTime")));
		}
		if(condition.get("endUpdateTime") != null) {
			criteria.add(Restrictions.le("modifyDate", condition.get("endUpdateTime")));
		}
		criteria.setProjection(null);
		criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
		
		return criteria.list();
	}

}
